
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">

    <title>后台</title>

    <link href="__PUBLIC__/images/favicon.ico" rel="shortcut icon" />

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/bootstrap-theme.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/select2/select2.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/js/bootstrap-table/bootstrap-table.min.css" />
    <link rel="stylesheet" href="__PUBLIC__/css/dashboard.css" />
</head>

<body>

<include file="Common/topNav" />

<div class="container-fluid">
    <div class="row">
        <include file="Common/leftMenu" />
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="cont-title clearfix">
                <div class="title">任务分配列表</div>
            </div>
            <div class="table-responsive">
                <table class="table table-striped table-hover" id="tableData">
                    <thead>
                    <tr>
                        <th>序号</th>
                        <th style="text-align: left;">楼宇名</th>
                        <th>地址</th>
                        <th>扫楼人员</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <volist name="houses['list']" id="house">
                        <tr>
                            <td>{$key+1}</td>
                            <td style="text-align: left;">{$house.name}</td>
                            <td>{$house.position}</td>
                            <td>
                                <volist name="house['sweep']" id="admin">
                                    <if condition="$key eq 0">
                                        {$admin.real_name}
                                        <else />
                                        ,{$admin.real_name}
                                    </if>
                                </volist>
                            </td>
                            <td>
                                <a thisId="{$house['id']}" class="setHouseAdmin" href="javascript:void(0);">扫楼人员设置</a>
                            </td>
                        </tr>
                    </volist>
                    </tbody>
                </table>
                <div class="page">
                    {$houses.page}
                </div>
            </div>
        </div>
    </div>
</div>


<include file="Common/modalHtmls" />

<script type="text/javascript" src="__PUBLIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/bootstrap-table/bootstrap-table-locale-all.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/select2/select2.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
<script>

    $(function () {
        $(".setHouseAdmin").click(function(){
            var houseId = $(this).attr("thisId");
            common.htmlAjax("{:U('Admin/Check/setSweeping')}",{id:houseId},function(html){
                //console.log(html);
                $("#commonModal").html(html).modal('toggle');
            });
        });
//            loadTableList();
//            $("#org_id").select2({
//                placeholder:'全部',
//                allowClear:true
//            });
//            $("#search_btn").bind("click",loadTableList);
    });

    function loadTableList() {
        var url = "{:U('Admin/Org/getOrgList')}";
        var columns = [
            //{checkbox: true,align: 'center'},
            {field: 'name',title: '机构名称',align: 'left',valign: 'middle'},
            {field: 'introduce',title: '简介',align: 'center',valign: 'middle'},
            {title: '地址',align: 'center',valign: 'middle',formatter:
                function (value,row,index) {
                    var text = row.address;
                    if(row.pid == 0 && row.county) {
                        text = row.province.name+"-"+row.city.name+"-"+row.county.name+"-"+row.address;
                    }
                    return text;
                }
            },
            {title: '管理员',align: 'center',valign: 'middle',formatter:
                function (value,row,index) {
                    var text = '';
                    var admins = row.admins;
                    $.each(admins,function (index,item) {
                        if(index == 0) {
                            text = item.real_name;
                        } else {
                            text += ','+item.real_name;
                        }
                    });
                    return text;
                }
            },
            {title: "操作",align: 'center',valign: 'middle',formatter:
                function (value, row, index) {
                    var btn = '<a thisId="'+row.id+'" class="editOrg" href="javascript:void(0);">修改</a> | ';
                    btn += '<a thisId="'+row.id+'" class="setHouseAdmin" href="javascript:void(0);">管理员设置</a>';
                    return btn;
                }
            }
        ];
        var options = {};
        var param = {
            pid: $("#org_id").val()
        };

        common.loadTableData("tableData",url,columns,param,options,function () {
            $(".pagination-detail").remove();
            $(".deleteOrg").click(function(){
                var orgId = $(this).attr("thisId");
                common.confirm("提示","确定删除组织机构?",function(){
                    common.ajax("{:U('Admin/Org/delOrg')}",{orgId:orgId},function(data){
                        //console.log(data);
                        common.alert("提示","组织机构删除成功!",function(){
                            common.reload();
                        });
                    })
                })
            });


            $(".setHouseAdmin").click(function(){
                var orgId = $(this).attr("thisId");
                common.htmlAjax("{:U('Admin/Check/setHouseAdmin')}",{orgId:orgId},function(html){
                    //console.log(html);
                    $("#commonModal").html(html).modal('toggle');
                });
            });
        });
    }

</script>
</body>
</html>
